<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const arr = [1, 3, 2, 6, 15, 12, 10];
        function pop (arr) {
            const res = [];
            while (arr.length > 0) {
                let maxIdx = 0;
                for (let i = 0; i < arr.length; i++) {
                    const item = arr[i];
                    if (item > arr[maxIdx]) {
                        maxIdx = i;
                    }
                }
                const max = arr.splice(maxIdx, 1)[0];
                res.unshift(max);
            }
            return res;
        }
        console.log(pop(arr));
    </script>
</body>
</html>